package cn.android.support.v7.lib.sin.crown.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import cn.android.support.v7.lib.sin.crown.R;
import cn.android.support.v7.lib.sin.crown.base.BaseApplication;
import cn.android.support.v7.lib.sin.crown.kotlin.common.px;


/**
 * @author 彭治铭
 */
public class ToastUtils {
    public static View getView(Context context, int layoutId) {
        LayoutInflater mInflater = LayoutInflater.from(context);
        View view = mInflater.inflate(layoutId, null);
        return view;
    }

    public static Toast toast;
    public static TextView textView;

    public static void showToastView(String text) {
        if (toast == null) {
            toast = new Toast(BaseApplication.getInstance());
            toast.setGravity(Gravity.CENTER | Gravity.BOTTOM, 0, px.INSTANCE.y(160));// 显示位置
            toast.setDuration(Toast.LENGTH_SHORT);// 显示时长，1000为1秒
            View view = getView(BaseApplication.getInstance(), R.layout.crown_layout_toast);
            textView = (TextView) view.findViewById(R.id.crown_tost_text);
            textView.setText(text);
            ProportionUtils.getInstance().adapterTextView(textView);
            view.getBackground().setAlpha(200);// 设置透明度。0~255，0完全透明。255不透明。
            toast.setView(view);// 自定义view
            toast.show();
        } else {
            textView.setText(text);
            toast.show();
        }

    }

}
